<!DOCTYPE html>
<html lang="en">
<head>
    <title>注册或登录</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="format-detection" content="telephone=no,email=no">
    <script type="text/javascript" src="/static/h5/js/flexible.min.js"></script>
    <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/h5/css/m.css">
</head>
<body>

<div class="page bind-page page-login">

    <div class="bind-logo bl2"><img src="/static/h5/images/background.png"></div>

    <form class="login-form bind-form">
        <div class="item">
            <div class="bd"><input type="text" name="" class="bind-input mobile" placeholder="请输入手机号"></div>
            <div class="fd"><a href="javascript:" class="login-code-btn get_code">发送验证码</a></div>
        </div>
        <div class="item">
            <div class="bd"><input type="text" name="" class="bind-input code" placeholder="请输入短信验证码"></div>
        </div>
        <div class="submit-box">
            <a href="javascript:" class="ui-btn bind_mobile">登录</a>
        </div>
        <div class="xieyi"></div>
    </form>
    <div class="bottom"></div>
</div>
<script type="text/javascript" src="/static/lib/layer_mobile/layer.js"></script>
<script type="text/javascript">
    var getCodeStatus = 0;
    var countdown=60;
    var bind_name = 'input';
    if (navigator.userAgent.indexOf("MSIE") != -1){
        bind_name = 'propertychange';
    }
    function checkMobile(mobile){
        var partten = /^1[0-9]{10}$/;
        if(partten.test(mobile)){
            return true;
        }else{
            return false;
        }
    }
    function _alert(msg){
        layer.open({
            content: msg
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
        });
    }
    $(function () {
        $('.mobile').bind(bind_name,function () {
            if(checkMobile($(this).val())){
                getCodeStatus = 1;
                $('.get_code').addClass('btn_check');
                $('.get_code').removeAttr('disabled');
            }else{
                getCodeStatus = 1;
                $('.get_code').removeClass('btn_check');
                $('.get_code').attr('disabled',true);
            }
        });


        $('.get_code').click(function () {
            var mobile = $('.mobile').val();
            if(getCodeStatus == 0 ){return false;}
            if( mobile == ''){
                _alert('请输入手机号');
                return false;
            }
            var settime = function () {
                if (countdown == 0) {
                    $('.get_code').removeAttr('disabled');
                    $('.get_code').html("获取验证码");
                    getCodeStatus = 1;
                    countdown = 60;
                    return false;
                } else {
                    $('.get_code').attr('disabled', true);
                    $('.get_code').html("重新发送(" + countdown + ")");
                    countdown--;
                    setTimeout(function(){
                        settime();
                    },1000)
                }
            }
            $.post('/h5/send.sms.code',{mobile:mobile},function(data){
                if(data.status == 1){
                    getCodeStatus = 0;
                    settime();
                }else{
                    _alert(data.msg);
                    return false;
                }
            });
        });
        $(".bind_mobile").click(function(){
            var mobile = $('.mobile').val();
            var sms_code = $('.code').val();
            if(!checkMobile(mobile)){
                _alert('请输入正确的手机号');
                return false;
            }
            if(sms_code == ''){
                _alert('请填写验证码');
                return false;
            }

            $.post('/h5/login.do?code={$code}',{mobile:mobile,sms_code:sms_code},function (data) {
                if(data.status === 1){
                    window.location.href = '/h5/home';
                    return true;
                }
                _alert(data.msg);
            })
        });
    });
</script>

</body>
</html>